package edu.pku.hawk.controller.util;

import edu.pku.hawk.controller.detectmonitor.DetectReport;

public class ReportQueue {
	
	int size = 10;
	DetectReport[] list ;
	int front = 0; 
	int rear= 0;
	int count = 0;
	
	public DetectReport get(int i)  {
		return list[i];
	}
	
	public int length() {
		return count;
	}
	
	public ReportQueue (int size ) {
		assert(size > 0);
		this.size= size;
		list  = new DetectReport[size];
	}
	
	public boolean empty () {
		return (front == rear);
	}
	
	public boolean full() {
		return ((rear + 1) % size) == 0 ? false : true;
	}
	
	public boolean enqueue (DetectReport t) {
		if (count == size) { 
			return false;
		}
		count ++;
		list[rear] = t;
		rear = (rear + 1) % size;
		return true;
	}
	
	public DetectReport dequeue() {
		if (count > 0) {
			DetectReport data = list[front];
			count --;
			front = (front + 1) % size ;
			return data;
		} else {
			return null;
		}
	}
	
	public DetectReport front () {
		if (count > 0) { 
			DetectReport ret = list[front];
			return ret;
		} else {
			return null;
		}
	} 
	
	public void clear() {
		front = 0;
		rear = 0;
		count = 0;
	}
	
	
	public static void main ( String[] str) {
		ReportQueue q = new ReportQueue(10);
		q.enqueue(new DetectReport());
		
		
	}
			

}
